#

| Chapter 3 |

# 3. Logging Out

Contents:
Running Commands When You Log Out
Running Commands at Bourne/Korn Shell Logout
Electronic Fortune Cookies
Automatic File Cleanup
Stop Accidental C Shell Logouts
Stop Accidental Bourne Shell Logouts
Detaching a Session with screen
What tty Am I On?

## 3.1 Running Commands When You Log Out

Is there something you want to do every time you log out: run a program that deletes temporary files, asks you a question, or prints a fortune to your screen? If you use the C shell, make a file named .logout (2.2) in your home directory and put the commands there. Before a login C shell exits, it'll read that file. But not all shells are login C shells; you might want these shells to read your logout-type file, too. Articles 2.7 and 2.8 have some suggestions.

Some ideas for your .logout are:

- A command like fortune (3.3) to give you something fun to think about when you log out.

- A background command to clean up temporary files, as in article 3.4.

- A command to list a "reminder" file - for example, work to take home.

- A script that prompts you for the hours you've worked on projects so you can make a timesheet later.

- The command clear (22.18) to erase your screen. This keeps the next user from reading what you did. [1] It also helps to stop "burn-in" damage to terminals caused by characters left over from your login session. (Some UNIXes clear the screen before printing the `login:` prompt. Of course, this won't help users who connect with a data switch (52.9) or port manager because the connection will be broken before the next login prompt.)

  > [1] Some terminals and windows have "scroll back" memory of previous screens. clear usually doesn't erase all of that.

If you connect to this host over a network, with a slow modem or on a data switch - and you don't see all the .logout commands run before your connection closes - try putting the command `sleep 2` (40.2) at the end of the file. That makes the shell wait two seconds before it exits, which gives output more time to get to your screen.

- JP

2.16 Approved Shells: Using Unapproved Login Shell |  | 3.2 Running Commands at Bourne/Korn Shell Logout